package com.jiyun.demo;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

import java.util.HashMap;
import java.util.Map;

public class Insert {
    public static void main(String[] args) {
        //创建链接
        MongoClient client = new MongoClient("127.0.0.1");
        //获取数据库
        MongoDatabase database = client.getDatabase("2108a");
        //获取集合
        MongoCollection<Document> user = database.getCollection("user");
        //创建map集合插入数据
        Map<String,Object>map = new HashMap();
        map.put("content","日照香炉生紫烟");
        map.put("userid","3306");
        map.put("visits",6666);
        Document document = new Document(map);
        user.insertOne(document);
        client.close();
    }
}
